﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace VTFC
{
    // ----------------------------------------------------------------------------
    /// <summary>
    /// Configuration editor form.
    /// </summary>
    // ----------------------------------------------------------------------------
    public partial class FrmConfig : Form
    {
        // ----------------------------------------------------------------------------
        /// <summary>
        /// Constructor.
        /// </summary>
        // ----------------------------------------------------------------------------
        public FrmConfig()
        {
            InitializeComponent();
            InitializeContent();
            Initialize();
        }//ctor

        private void InitializeContent()
        {
            this.Text = Resources.FrmConfig_Text;
            this.lblAutoConnect.Text = Resources.FrmConfig_AutoConnect;
            this.btnOk.Text = Resources.ButtonOk;
            this.btnCancel.Text = Resources.ButtonCancel;
        }//func InitializeContent

        private void Initialize()
        {
            nudConnectionTimeout.Maximum = Decimal.MaxValue;
            ckbAutoConnect.Checked = ConfigManager.GetBoolean(Constant.VTFC_CONFIGURATION_AUTOCONNECT);
            nudConnectionTimeout.Value = ConfigManager.GetInt32(Constant.VTFC_CONFIGURATION_CONNECTIONTIMEOUT);
        }//func Initialize

        private void btnOk_Click(object sender, EventArgs e)
        {
            Dictionary<string, string> configvalues = new Dictionary<string,string>();
            configvalues.Add( Constant.VTFC_CONFIGURATION_AUTOCONNECT, ckbAutoConnect.Checked.ToString());
            configvalues.Add(Constant.VTFC_CONFIGURATION_CONNECTIONTIMEOUT, nudConnectionTimeout.Value.ToString());
            
            ConfigManager.SaveConfiguration(configvalues);

            this.DialogResult = DialogResult.OK;
        }//func btnOk_Click
    }//class FrmConfig
}//namespace VTFC
